package com.ynsj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynsj.mapper.UserBankMapper;
import com.ynsj.domain.UserBank;
import com.ynsj.service.UserBankService;
@Service
public class UserBankServiceImpl extends ServiceImpl<UserBankMapper, UserBank> implements UserBankService{

    /**
     * 分页查询会员银行卡信息
     *
     * @param page
     * @param userId
     * @return
     */
    @Override
    public Page<UserBank> findBankByPage(Page<UserBank> page, Long userId) {
        page.addOrder(OrderItem.desc("last_update_time"));
        return page(page,new LambdaQueryWrapper<UserBank>().eq(userId!=null,UserBank::getUserId,userId));
    }

    /**
     * 启用/禁用银行卡信息
     *
     * @param id
     * @param status
     * @return
     */
    @Override
    public boolean updateStatus(Long id, Integer status) {
        return update(new LambdaUpdateWrapper<UserBank>()
                .eq(id!=null,UserBank::getId,id)
                .set(status!=null,UserBank::getStatus,status));
    }

}
